import 'package:flutter/material.dart';

import  '../utils/toast.dart';
import 'package:provider/provider.dart';
import 'package:qaun_ni_dev/provider/loginProvider.dart';
import 'package:qaun_ni_dev/home_page.dart';
class Login extends StatefulWidget {
  @override
  _LoginState createState() => _LoginState();
}

class _LoginState extends State<Login> {
  TextEditingController userName = TextEditingController(text: 'admin');
  TextEditingController userPwd = TextEditingController(text: '123456');

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        title: Text('圈你后台管理系统'),
      ),
      body: Container(
          padding: EdgeInsets.all(10.0),
          child:Center(
            child: Column(
//            mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Container(
                  width: 60,
                  margin: EdgeInsets.only(top: 20,bottom: 20),
                  child: Image.asset('assets/images/quanniLogo.png',fit: BoxFit.cover,),
                ),
                TextField(
                  controller: userName,
                  autofocus: false,
                  decoration: InputDecoration(
                      labelText: '用户名',
                      hintText: '你的用户名',
                      prefixIcon: Icon(Icons.person)),
                  onChanged: (v) {
//              print({'打印内容': v});
                  }, // 实时监听输入框的变化
                ),
                TextField(
                  controller: userPwd,
                  autofocus: false,
                  obscureText: true, // 密码变为点点
                  keyboardType: TextInputType.text,
                  decoration: InputDecoration(
                    labelText: '密码',
                    hintText: '输入你的密码',
                    prefixIcon: Icon(Icons.lock),
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(top: 20),
                  child: RaisedButton(
                    onPressed: () {
                      _login();
//                      _login2();
                    },
                    child: Text('登录'),
                    padding: EdgeInsets.only(left: 50.0, right: 50.0),
                    colorBrightness: Brightness.dark,
                    color: Colors.lightBlue,
                    splashColor: Colors.grey,
                  ),
                )
              ],
            ),
          )
      ),
    );
  }

  void _login() {
    print({'username': userName.text, 'userpwd': userPwd.text});
    if(userName.text == '' || userPwd.text == '') {
      Toast.toast(context,msg: "请输入账号信息！");
    } else {
      Provider.of<LoginProvider>(context,listen: false).loginCheck(context, userName.text,userPwd.text);
    }
  }

  void _login2 () {
    Navigator.push(context, MaterialPageRoute(
        builder: (context) {
          return HomePage();
        }
    ));
  }


}
